package cn.lxs.web.servletContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ContextDemo2")
public class ContextDemo2 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //通过  Http来获取
        ServletContext context = this.getServletContext();
        //定义一个文件名称
        String filename = "a.jpg";
        //获取 MINE 类型
        String mimeType = context.getMimeType(filename);
        System.out.println(mimeType);
        //image/jpeg

    }
}
